var settings = new function(){
	
	var   _$window
		, _$infoBtn
		, _$audioFile
		, _$audioTitle
	;
	
	
	function _init(){
		
		_$window = $('#settings-window');
		_$infoBtn = $('#info-btn');
		_$audioFile = $('#bg-music');
		_$audioTitle =$('#bg-music-title');
		
		//kendo window
		_$window.kendoWindow({
			  width: "600px"
			, height: "355px"
			, title: "Configuración del libro"
			, modal: true
			, visible: false
			, draggable: false
			, resizable: false
		});
		
		_$audioFile.kendoUpload({
        	async: {
                saveUrl: "/upload",
                autoUpload: true
            },
            multiple: false,
            showFileList: false,
            success: function(data) {uploadComplete(data)},
            error: function(data) {uploadComplete(data)},
            localization: {
            	select: "Seleccionar"
            }
		});
		
		
		/*
		 * Funcionalidad de los botones
		 */
		_$infoBtn.on('click', function(){
			
			_open();
		})
	}
	
	
	function _open(){
		
		_$window.data("kendoWindow").center().open();
	}
	
	
	function getAudio(){
		
		return $('#bg-music').val();
	}
	
	
	function uploadComplete(data){
		
		var extension = data.files[0].extension;
		
		if (extension != ".mp3" && extension != ".ogg" && extension != ".wav"){
			
			_$audioTitle.text('ERROR. La extensión del archivo de audio no es correcta.');
		}
		else {
			
			var fileName = data.files[0].name;
	    	window.console.log('Audio subido correctamente: ' + fileName);
	    	_$audioTitle.text(fileName);
	    	previewController.initAudio = "/getFile?fileName=" + fileName;
	    	previewController.bookAudio.src = "/getFile?fileName=" + fileName;
		}
	}
	
	
	this.init = _init;
	this.getAudio = getAudio;
}